package com.zry.traced.ui.activity


import android.content.Intent
import com.zry.traced.R
import com.zry.traced.adapter.ComplementCodeAdapter
import com.zry.traced.animation.RecyclerViewUtilKt
import com.zry.traced.been.HomePageBean
import com.zry.traced.databinding.ActivityComplementCodeBinding
import com.zry.traced.ui.base.BaseActivity
import com.zry.traced.utils.HomePageList
import kotlinx.android.synthetic.main.activity_complement_code.*
import kotlinx.android.synthetic.main.common_title.*

class ComplementCodeActivity : BaseActivity() {
    private var complementCodeBinding: ActivityComplementCodeBinding? = null
    private var title = ""
    override fun getLayoutId(): Int {
        return R.layout.activity_complement_code
    }

    override fun initData() {
        title = intent.getStringExtra("title")
        titleCenterText.text = title
        commonLeftLinearLayout.setOnClickListener { finish() }
        complementCodeBinding = viewDataBinding as ActivityComplementCodeBinding

        initView()
    }

    private fun initView() {
        recyclerViewUtilKt = RecyclerViewUtilKt(this, complementCodeRecycler)
        recyclerViewUtilKt?.initRecyclerView()

        when (title) {
            "补码拆码" -> {
                initAdapter(HomePageList().getComplementCodeList())
            }
            "操作记录" -> {
                initAdapter(HomePageList().getOperationRecord())
            }
            "本地数据" -> {
                initAdapter(HomePageList().getLocalData())
            }
        }
    }

    private fun initAdapter(homePageList: MutableList<HomePageBean>) {
        val complementCodeAdapter = ComplementCodeAdapter(R.layout.item_complement_code, homePageList)
        recyclerViewUtilKt?.setAdapter(complementCodeAdapter)
        complementCodeAdapter.setOnItemClickListener { adapter, view, position ->
            val title = homePageList[position].homePageName
            when (title) {
                "补码入箱", "拆码出箱" -> {
                    val intent = Intent(this, ComplementInBoxActivity::class.java)
                    intent.putExtra("title", title)
                    startActivity(intent)
                }
                "入库记录", "出库记录", "打包记录", "补码记录", "拆码记录" -> {
                    val intent = Intent(this, OperationRecordActivity::class.java)
                    intent.putExtra("title", title)
                    startActivity(intent)
                }
                "未上传入库记录", "未上传出库记录", "未上传打包记录" -> {
                    val intent = Intent(this, LocalDataListActivity::class.java)
                    intent.putExtra("title", title)
                    startActivity(intent)
                }
            }
        }
    }
}
